function twitterCallback2(obj) {
	var twitters = obj;
	var statusHTML = "<ul>";
	var username = "";
	for (var i=0; i<twitters.length; i++){
		username = twitters[i].user.screen_name;
		text = twitters[i].text;
		text = text.replace(/(http:[\S]+)/g, "<a href='$1'>$1</a>");
		text = text.replace(/(@*)([\S]+)(\+\+)/g, "$1$2<a href='http:\/\/plusplusbot.com/targets\/$2' rel='vote-for'>$3<\/a>");
		text = text.replace(/(@*)([\S]+)(\-\-)/g, "$1$2<a href='http:\/\/plusplusbot.com/targets\/$2' rel='vote-against'>$3<\/a>");
		text = text.replace(/@([\w]+)/g, "@<span class='vcard'><a href='http:\/\/twitter.com/$1' class='fn' rel='contact'>$1<\/a></span>");
		text = text.replace(/#([^\s].*)#[^\S]/g, "#<a href='http:\/\/www.technorati.com\/tag\/$1' rel='tag'>$1<\/a># ");
		text = text.replace(/#([^<\s][\S]+)/g, "#<a href='http:\/\/www.technorati.com\/tag\/$1' rel='tag'>$1<\/a>");
		text = text.replace(/L:(.*)/, "L:<a href='http:\/\/maps.google.com/maps?f=q&q=$1'>$1<\/a>");
		
		//<abbr class="dtstart" title="1998-03-12T08:30:00-05:00">12 March 1998 from 8:30am EST</abbr>
		
		statusHTML += ('<li><span>'+text+'</span> '
			+ '<a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'
			+ '<abbr class="published" title="' + iso_time(twitters[i].created_at) + '">'
			+ relative_time(twitters[i].created_at)
			+ '</abbr></a></li>');
	}
	statusHTML += "</ul>";
	document.getElementById('twitter_div').innerHTML = statusHTML;
}

function iso_time(time_value) {
    var values = time_value.split(" ");
    time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
    var d = new Date(time_value);	
    var year = d.getUTCFullYear();
    if (year < 1970) year = year + 100;
    return String(year)+"-"
		+f2(new String(d.getUTCMonth() + 1))+"-"
		+f2(new String(d.getUTCDay()))+"Z"	 
		+f2(d.getUTCHours())+":"
		+f2(d.getUTCMinutes())+":"
		+f2(d.getUTCSeconds());
}

function f2(n) {
	ns = new String(n);
	if (ns.length == 1) ns = "0" + ns;
	return ns;
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}
